class home
    extends Scene implements eui.UIComponent {
    protected onComplete() {

        this.waterWave.touchEnabled=true;
        this.waterWave.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onTouch,this);

        this.lottery.touchEnabled = true;
        this.lottery.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onLottery,this);

        this.friend.touchEnabled= true;
        this.friend.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onFriend,this);

        this.water.touchEnabled= true;
        this.water.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onWater,this);
    }

    private onFriend(event:egret.TouchEvent):void{
        let f:FriendHome = new FriendHome();
        SceneManager.Instance.changeScene(f);
    } private onWater(event:egret.TouchEvent):void{
        let d:Dynamic = new Dynamic();
        SceneManager.Instance.pushScene(d);
    }
    private onLottery(event:egret.TouchEvent):void{
        let te:Lottery = new Lottery();
        SceneManager.Instance.changeScene(te);
    }



/**
     * 显示对象可以作为另一个显示对象的遮罩, 作为遮罩的对象最好也添加的舞台中
     * 遮罩后, 被遮罩的显示对象只有和遮罩的显示对象重叠的部分才会显示
     */
    private onAddToStage() {

        //画一个红色的正方形
        var square:egret.Shape = new egret.Shape();
        square.graphics.beginFill(0xffffff);
        square.graphics.drawRect(0,1060,750,175);
        square.graphics.endFill();

        square.alpha=0.2;
        this.addChild(square);

        //画一个蓝色的圆形
        // var circle:egret.Shape = new egret.Shape();
        // circle.graphics.beginFill(0x0000ff);
        // circle.graphics.drawCircle(25,25,25);
        // circle.graphics.endFill();
        // this.addChild(circle);
        // square.mask = circle;
    }

    //给头像添加圆形遮罩
    private setCircleMaskHead(head: egret.Bitmap):void{
        //
        //画一个蓝色的圆形
        var circle: egret.Shape = new egret.Shape();        
        //
        circle.graphics.beginFill(0x0000ff);
        //circle.graphics.lineStyle(2,0x00ff00);
        circle.graphics.drawCircle(20/ 2,20 / 2,20/2);
        circle.graphics.endFill();
        this.addChild(circle);
        head.mask = circle;
        //
       
    }

    public constructor() {
        super();
    }

    protected partAdded(partName: string, instance: any): void {
        super.partAdded(partName, instance);
    }

    /**
     * EXML中对应id为tweenGroup的动画组对象
     */
    public water1: egret.tween.TweenGroup;

    public cloud_left: egret.tween.TweenGroup;

    public cloud_right: egret.tween.TweenGroup;

    public random: egret.tween.TweenGroup;
    public random2: egret.tween.TweenGroup;

    public waterWave: eui.Image;

    public windMill: egret.tween.TweenGroup;


    public lottery: eui.Button;
    public water: eui.Button;


    public friend:eui.Image;

    /**
     * 循环播放动画
     */
    protected playAnimation(target: egret.tween.TweenGroup, isLoop: boolean): void {
        if (isLoop) {
            for (var key in target.items) {
                target.items[key].props = {loop: true};
            }
        }
        target.play();
    }

    protected childrenCreated(): void {
        this.onAddToStage();
        super.childrenCreated();
        //this.testFunc(this.waterGroup,0x000000, 0.8);
        this.playAnimation(this.water1, true);
        this.playAnimation(this.cloud_left, true);
        this.playAnimation(this.cloud_right, true);
        this.playAnimation(this.random, true);
        this.playAnimation(this.random2, true);
        this.playAnimation(this.windMill, true);

        

        //this.waterGroup.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouch, this);


        // this.water1.play(500);
    }

    private onTouch(event:egret.TouchEvent):void {
        //var btn: eui.Button = <eui.Button>event.target;
        let testStage: Lottery = new Lottery();
        SceneManager.Instance.changeScene(testStage);
        //this.addChild(testStage);
    }


    /**
     * 这里是反向遮挡函数
     */
    private testFunc(target: egret.DisplayObject, bgColor: number, alpha: number) {
        let container: egret.DisplayObjectContainer = new egret.DisplayObjectContainer();

        let blendShape = new egret.Shape();					 	// 用来作为遮挡背景
        blendShape.graphics.beginFill(bgColor, alpha);
        blendShape.graphics.drawRect(0, 0, this.width, this.height);
        blendShape.graphics.endFill();
        container.addChild(blendShape);
        container.addChild(target);
        target.blendMode = egret.BlendMode.ERASE;

        let renderTexture: egret.RenderTexture = new egret.RenderTexture();
        renderTexture.drawToTexture(container);
        let blendBitmap = new egret.Bitmap(renderTexture);
        this.addChild(blendBitmap);

        blendBitmap.touchEnabled = true;  // 允许点击
        blendBitmap.pixelHitTest = true;  // 是否开启精确像素碰撞。设置为true显示对象本身的透明区域将能够被穿透。
    }


}